package com.contory.ssn_lgnd.app.maingame;

import java.util.ArrayList;
import java.util.LinkedList;

import android.util.Log;

import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.framework.Pool;
import com.contory.ssn_lgnd.framework.Pool.PoolObjectFactory;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;
import com.contory.ssn_lgnd.framework.math.Vector2;

public class Fire implements UpdatePtr, DrawPtr{
	LinkedList<BulletObjectPtr> bulletList;
	//Pool<BulletObjectPtr> bulletPool;
	final ColisionManager cm;
	
	public Fire(ColisionManager cm){
		//bulletPool = new Pool<BulletObjectPtr>(factory, 30);
		bulletList = new LinkedList<BulletObjectPtr>();
		this.cm = cm;
	}
	
	@Override
	public void draw(SpriteBatcher batcher) {
		if(bulletList.size() < 1)
			return;
		for (BulletObjectPtr bulletChd : bulletList) 
			bulletChd.draw(batcher);
	}
	
	@Override
	public void update(float deltaTime) {
		if(bulletList.size() < 1)
			return;
		updateBulletList(deltaTime);
	}
	
	private void updateBulletList(float deltaTime){
		for(int i = 0; i < bulletList.size(); i++){
			BulletObjectPtr bulletChd = bulletList.get(i);
			if(bulletChd.getEnabled())
				bulletChd.update(deltaTime);
			else{
				//bulletPool.free(bulletChd);
				bulletList.remove(bulletChd);
			}
		}
	}
	
	//Add bullet in list(= Shot)
	public void fire(BulletObjectPtr bullet){
		//bulletChd.setViewPos(strX, strY);
		//bulletChd.setTarget(target);
		//bulletChd.setColisionMG(cm);
		bulletList.add(bullet);
	}
}
